/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.comsrv.controller.c;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.security.annotation.Inner;
import com.ykht.proj.comsrv.entity.CnBanner;
import com.ykht.proj.comsrv.service.CnBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 轮播图
 *
 * @author proj
 * @date 2020-08-11 18:08:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("c/banner/" )
@Api(value = "lgbanner", tags = "c端轮播图")
public class CBannerController {

    private final CnBannerService cnBannerService;

    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "轮播图")
    @GetMapping("/bannerList" )
	@Inner(false)
    public R getLgBannerPage(CnBanner cnBanner) {
		cnBanner.setStatus(0);
        return R.ok(cnBannerService.list(Wrappers.query(cnBanner)).stream().sorted(Comparator.comparing(CnBanner::getSort)).collect(Collectors.toList()));
    }


    /**
     * 通过id查询轮播图
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(cnBannerService.getById(id));
    }

}
